package com.zhyt.intelligentpipeline.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhyt.intelligentpipeline.mapper.PipelineMapper;
import com.zhyt.intelligentpipeline.model.Pipeline;
import com.zhyt.intelligentpipeline.service.TrunkLineService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class TrunkLineServiceImpl implements TrunkLineService {

    @Resource
    private PipelineMapper pipelineMapper;

    @Override
    public Set<String> getTrunkLineNames() {
        Set<String> names = new HashSet<>();
        QueryWrapper<Pipeline> queryWrapper = new QueryWrapper<>();
        List<Pipeline> pipelines = pipelineMapper.selectList(queryWrapper);
        for (Pipeline pipeline : pipelines) {
            names.add(pipeline.getTrunkLine());
        }
        return names;
    }

    @Override
    public List<Pipeline> getPipelineByTrunkLineName(String trunkName) {
        QueryWrapper<Pipeline> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Pipeline::getTrunkLine,trunkName);
        return pipelineMapper.selectList(queryWrapper);
    }
}
